#!/bin/csh -f

#-------------------------------------------------------------------------------
# This script runs Naturals Docs to generate the UVM Reference Documentation
# from comments embedded in the UVM source.
#
# Before running NaturalDocs, this script will remove any existing html output
# directory, which is fixed at $UVM_HOME/distrib/docs/html. It then copies the UVM logo,
# banner, other gifs from the $ND source dir to the outdir. NaturalDocs will not
# do this for us, as we've customized the page layout.
#
# Next, the script runs NaturalDocs proper, which requires that perl be in your
# search PATH. The command line uses the following options: 
#
# -do  - include only source files that contain documentation
#
# -ro  - rebuild the output from scratch each time (this actually isn't needed
#        since we delete any previously existing output before running
#
# -i   - sets the input directories from which to gather documentation,
#        $UVM_HOME/distrib/src and $UVM_HOME/uvm_ref. The latter directory
#        contains various overview text files.
#
# -img - sets the directories from which to find the images referenced in the
#        source documentation: (see <filename>.gif). We have one such input
#        directory, ./Images
#
# -p   - sets the project directory into which the Menu.txt, Languages.txt,
#        and Topics.txt files are written. Only the Menu.txt is of interest.
#
# -o   - sets the output directory into which self-contained HTML documentation
#        is written. We choose to use the FramedHTML option so the menu is
#        always present on the left hand side of the browser window.
#
# To learn more on these and other NatualDocs options, type 'perl NaturalDocs -h'
# You can also visit naturaldocs.org.
#
# NaturalDocs will finish with an error if the Proj/* files are not writable.
# That's OK if you have not added any source files with documentation and only
# want to regenerate the HTML.
#
# If you have added source files with documentation, you will need to 'check out'
# the Proj/Menu.txt file so that NaturalDocs can update it with initial entries
# for each added file. You then edit the Menu.txt to move the entries to the
# desired location in the menu. You should always "lock-in" the name of each
# menu item by adding the 'no auto-title' option as shown in all current entries
# in Menu.txt.
#
#
#-------------------------------------------------------------------------------

set nd_dir = ../../natural_docs
set outdir = ../../distrib/docs/html
set uvm_root = `pwd | sed "s?/uvm_ref/nd??"`

echo "Uvm_root dir is $uvm_root"
echo "Output dir is $outdir"

rm -rf $outdir

mkdir -p $outdir/images

# copy source tree into html dir so links to the source resolve
cp        -r ../../distrib/src $outdir/src
mkdir     $outdir/src/overviews
cp        ../*.txt $outdir/src/overviews
mkdir     $outdir/src/overviews/relnotes
cp        ../relnotes/*.txt $outdir/src/overviews/relnotes

# replace UVM_ROOT in UVM_Menu.txt with current working dir to satisfy ND
# without requiring the source-controlled Menu file to be overwritten
# can get generated where ever checkedout
sed "s?UVM_ROOT?$uvm_root?g" $uvm_root/uvm_ref/nd/Proj/UVM_Menu.txt > $uvm_root/uvm_ref/nd/Proj/Menu.txt
cp        $uvm_root/uvm_ref/nd/Proj/UVM_Topics.txt    $uvm_root/uvm_ref/nd/Proj/Topics.txt
cp        $uvm_root/uvm_ref/nd/Proj/UVM_Languages.txt $uvm_root/uvm_ref/nd/Proj/Languages.txt
chmod 666 $uvm_root/uvm_ref/nd/Proj/Languages.txt
chmod 666 $uvm_root/uvm_ref/nd/Proj/Menu.txt
chmod 666 $uvm_root/uvm_ref/nd/Proj/Topics.txt

cp -r $nd_dir/images/b* $outdir/images
cp    $nd_dir/logo.html $outdir

# Run ND
cp ./Proj/Menu.txt log

perl $nd_dir/NaturalDocs \
  -q \
  -do \
  -ro \
  -i $outdir/src \
  -img ./Images \
  -p ./Proj \
  -o FramedHTML $outdir

